package com.violet.sharding.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.violet.sharding.domain.AlarmDomain;
import com.violet.sharding.mapper.AlarmMapper;
import com.violet.sharding.service.AlarmService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;

/**
 * @Author: wqf
 * @Date: 2023/01/06
 * @Description:
 */
@Service
public class AlarmServiceImpl implements AlarmService {

    @Resource
    private AlarmMapper alarmMapper;

    /**
     * 方法描述: 按时间范围查询告警信息
     *
     * @param startTime 查询开始时间
     * @param endTime   查询结束时间
     * @return java.util.List<com.violet.sharding.domain.AlarmDomain>
     * @author wqf
     * @date 2023/1/9 16:45
     */
    @Override
    public List<AlarmDomain> queryList(LocalDateTime startTime, LocalDateTime endTime) {
        return alarmMapper.selectList(new LambdaQueryWrapper<AlarmDomain>()
                .gt(AlarmDomain::getCreateTime, startTime)
                .lt(AlarmDomain::getCreateTime, endTime)
        );
    }

    /**
     * 方法描述:
     *
     * @param startTime
     * @param endTime
     * @return java.util.List<com.violet.sharding.domain.AlarmDomain>
     * @author wqf
     * @date 2023/1/10 14:16
     */
    @Override
    public AlarmDomain queryOne(LocalDateTime startTime, LocalDateTime endTime) {
        return alarmMapper.selectOne(startTime, endTime);
    }

    @Override
    public void save() {
        AlarmDomain alarmDomain = new AlarmDomain();
        alarmDomain.setAlarmContent("这是一个测试数据");
        alarmDomain.setId(10001L);
        alarmDomain.setCreateTime(LocalDateTime.now());
        alarmMapper.insert(alarmDomain);
    }

    @Override
    public void delete(Long id) {
        alarmMapper.delete(new LambdaQueryWrapper<AlarmDomain>()
                .eq(AlarmDomain::getAlarmId, id)
                .lt(AlarmDomain::getCreateTime, LocalDateTime.now()));
    }


}
